<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../00.依赖包/react.development.js"></script>
  <script src="../00.依赖包/react-dom.development.js"></script>
  <script src="../00.依赖包/babel.min.js"></script>
</head>

<body>
  <div id="app"></div>
  <script type="text/babel">
    class Father extends React.Component{
      /* 
      porps是用来做父子组件通信的
        - 在父组件中使用子组件的时候,可以给子组件添加属性
        - 在子组件中组件实例的props属性上,就能拿到这个属性和值
      */
      state={
        car:'八手奥拓'
      }
      render(){
        const {car} = this.state
        return(
          <div>
            <h1>我是老头</h1>
            <p>我开的车是{car}</p>
            <button onClick={this.changeCar}>赚钱了</button>
            <hr/>
            <Son car={car}/>  
          </div>
        )
      }
      changeCar=()=>{
        this.setState({car:'奥迪RS7'})
      }
    }
    class Son extends React.Component{
      /* 
        当父组件更新状态的时候,子组件的render方法会重新执行生成新的虚拟DOM,也能拿到最新的props
      */
      render(){
        //props对象及内部的属性都是只读的!!!!!! 禁止修改
        // this.props.car1 += "粉色的" 

        //当把props解构出来以后,我们可以修改解构出来的变量
        console.log(this,'儿子的this');
        let {car} = this.props
        car = '银灰色的'+car
        return(
          <p>我是儿子,开我老头的{car}</p>
        )
      }
    }

    const root = ReactDOM.createRoot(document.getElementById('app'));
    root.render(<Father/>)
  </script>
</body>

</html>